<template>
  <div class="login-container">
    <div class="form">
      <el-card shadow="never" class="login-card">
        <img
          src="https://likede2-admin.itheima.net/img/logo.595745bd.png"
          alt=""
          class="img_logo"
        >

        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="loginName">
            <el-input v-model="form.loginName" placeholder="请输入账号" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="form.password"
              placeholder="请输入密码"
              type="password"
            />
          </el-form-item>
          <el-form-item prop="code" class="input_flex">
            <el-row>
              <el-col
                :span="17"
              ><el-input
                v-model="form.code"
                placeholder="验证码"
                class="el_widths"
                style="width: 240px"
              /></el-col>
              <el-col
                :span="7"
              ><img
                :src="url + form.clientToken"
                class="img_width"
                @click="btn_img"
              ></el-col>
            </el-row>
          </el-form-item>
          <el-form-item>
            <el-button
              class="color_btn"
              style="width: 350px"
              type="primary"
              @click="submit"
            >
              登录</el-button>
          </el-form-item>
          <el-form-item>
            <p>仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！</p>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>
<script>
// import { login } from '@/api/user'
import { mapGetters } from 'vuex'
export default {
  name: 'Login',
  data() {
    return {
      form: {
        loginName: process.env.NODE_ENV === 'development' ? 'demo' : '',
        password:
          process.env.NODE_ENV === 'development' ? '888itcast.CN764%...' : '',
        loginType: 0,
        code: null,
        clientToken: Date.now()
      },
      url: 'https://likede2-java.itheima.net/api/user-service/user/imageCode/',
      random: null,
      rules: {
        loginName: [
          {
            required: true,
            message: '请输入手机号',
            trigger: 'blur'
          }
        ],
        password: [
          {
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }
        ],
        code: [
          {
            required: true,
            message: '请输入验证码',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'data'
    ])
  },
  methods: {
    btn_img() {
      this.form.clientToken = Date.now()
    },
    async submit() {
      try {
        await this.$store.dispatch('user/storeLogin', this.form)
        console.log(this.data)
        if (this.data.success) {
          console.log(1)
          this.$router.push('/')
          this.$message.success(this.data.msg)
        } else {
          this.$message.error('请检查用户信息')
        }
      } catch (error) {
        console.log(error)
      }
    }
  }

}
</script>
<style lang="scss">
.login-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url(https://likede2-admin.itheima.net/img/background.be4fae7d.png);
  background-repeat: no-repeat;
  background-size: cover;

  .form {
    display: flex;

    .el-card {
      position: relative;
      width: 518px;
      height: 450px;
      display: flex;
      justify-content: center;
      border: none;
      padding: 0;
      overflow:visible;
      padding-top: 40px;
      .img_logo {
        position: absolute;
       top: -40px;
       left: 210px;
       width: 80px;
       height: 80px;

      }
      .el-input {
        .el-input__inner {
          background: #f4f5fb;
        }
      }
      .el-checkbox {
        color: #606266;
      }
    }
  }
}
.img_width {
  height: 40px;
}
.color-btn {
  background: linear-gradient(262deg, #2e50e1, #6878f0);
}
p{
  margin: 0;
  padding: 0;
  width: 370px;
  color: red;
}
</style>
